/*
 * @Author: your name
 * @Date: 2021-10-12 09:56:21
 * @LastEditTime: 2021-10-15 22:16:08
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \luogu\动态规划\模板问题\P1049 装箱问题\main.cpp
 */

#include<stdio.h>
#include<iostream>
using namespace std;

#define max(a,b) (a > b) ? a : b

const int N = 31;
const int V = 20010;

//物品数组
int a[N];
//辅助数组 f[i][j] 前i个物品 对于空间j 最大价值(本题价值就是物体空间)
int f[N][V];

int main(){
    int v,n;
    cin >> v >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    for(int i=1; i<=n; i++){
        for(int j=0; j<=v;j++){
            f[i][j] = f[i-1][j];
            if(j >= a[i]){
                f[i][j] = max(f[i-1][j],f[i-1][j-a[i]]+a[i]);
            }
        }
        // cout << "i=" << i << endl;
        // for(int j=0; j<=v; j++){
        //     cout << "j=" << j << " ==> " <<f[i][j] << endl;
        // }
        // cout << endl;
    }
    cout << v-f[n][v];
}

